package emulator.util.file;

import java.io.File;

import emulator.util.AddressRange;

public class FileInfoRaw implements FileInfo {
	
	private int block_size;
	private int start_address;

	public FileInfoRaw(String file_name)
	{
		File file = new File(file_name);
		block_size = (int)file.length();
		start_address = -1;
		String file_extension = FileHelper.getFileExtension(file_name);
		if (file_extension.length() == 2 || file_extension.length() == 4)
		{
			try
			{
				int address = AddressRange.addressFromString("$"+file_extension);
				if (file_extension.length() == 2)
					address <<= 8;
				start_address = address;
			}
			catch (NumberFormatException e) { }
		}
	}

	@Override
	public int getBlockSize() {
		return block_size;
	}

	@Override
	public int getFormat() {
		return FileHelper.FILE_FORMAT_RAW;
	}

	@Override
	public int getStartAddress() {
		return start_address;
	}

	@Override
	public FileLoadStrategy getLoadStrategy() {
		return new FileLoadStrategyRaw();
	}

	@Override
	public FileSaveStrategy getSaveStrategy() {
		return new FileSaveStrategyRaw();
	}

}
